﻿// DlgTraySpacing.cpp: 实现文件
//

#include "stdafx.h"
#include "GHCY.h"
#include "DlgTraySpacing.h"
#include "afxdialogex.h"


// DlgTraySpacing 对话框

IMPLEMENT_DYNAMIC(DlgTraySpacing, CDialogEx)

DlgTraySpacing::DlgTraySpacing(StorePoint* psp, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_SETSPACING, pParent)
	, m_psp(psp)
	, m_nSpacing(psp->m_nDX)
	, m_nZNumber(psp->m_nZNumber)
	, m_nXNumber(psp->m_nXNumber)
	, m_nTotal(psp->m_nXNumber * m_nZNumber)
	, m_nLength(psp->m_nLength)
{
}

DlgTraySpacing::~DlgTraySpacing()
{
}

void DlgTraySpacing::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_nSpacing);
	DDV_MinMaxInt(pDX, m_nSpacing, 50, 10000);
	DDX_Text(pDX, IDC_EDIT2, m_nZNumber);
	DDV_MinMaxInt(pDX, m_nZNumber, 1, 10);
	DDX_Text(pDX, IDC_EDIT3, m_nXNumber);
	DDX_Text(pDX, IDC_EDIT4, m_nTotal);
	DDX_Text(pDX, IDC_EDIT5, m_nLength);
}


BEGIN_MESSAGE_MAP(DlgTraySpacing, CDialogEx)
	ON_BN_CLICKED(IDOK, &DlgTraySpacing::OnBnClickedOk)
	ON_EN_KILLFOCUS(IDC_EDIT1, &DlgTraySpacing::OnKillfocusEdit1)
	ON_EN_KILLFOCUS(IDC_EDIT2, &DlgTraySpacing::OnKillfocusEdit1)
END_MESSAGE_MAP()


// DlgTraySpacing 消息处理程序


void DlgTraySpacing::OnBnClickedOk()
{
	UpdateData(TRUE);

	m_psp->m_nXNumber = m_nXNumber;
	m_psp->m_nZNumber = m_nZNumber;
	m_psp->m_nDX = m_nSpacing;

	CString strsql;
	strsql.Format(L"UPDATE `point` SET `dx` = %i, `zNumber` = %i WHERE `id` = %i",
		m_nSpacing, m_nZNumber, m_psp->m_nPointID
	);	// ?? 异常
	theApp.getDatabase()->Execute(strsql);


	EndDialog(IDOK);
}


void DlgTraySpacing::OnKillfocusEdit1()
{
	UpdateData(TRUE);

	m_nXNumber = m_nLength / m_nSpacing;
	m_nTotal = m_nXNumber * m_nZNumber;

	UpdateData(FALSE);
}
